# Git 推送指南脚本
$gitPath = "C:\Program Files\Git\bin\git.exe"
$projectPath = "d:\MCP"
$remoteUrl = "https://gitee.com/yuzh0618/mess-mcp.git"

Set-Location -Path $projectPath
Write-Host "切换到项目目录: $projectPath"

# 检查Git状态
Write-Host "\n=== Git状态检查 ==="
& $gitPath status

# 检查远程仓库配置
Write-Host "\n=== 远程仓库配置 ==="
& $gitPath remote -v

# 选项1: 手动输入凭据推送
Write-Host "\n=== 选项1: 手动推送 (需要输入Gitee用户名和密码) ==="
Write-Host "用户名: yuzh0618"
Write-Host "密码: Yuzh0618@126.com"
Write-Host "执行以下命令进行推送:"
Write-Host "$gitPath push -u origin master"

# 执行推送命令
& $gitPath push -u origin master
if ($LASTEXITCODE -eq 0) {
    Write-Host "\n代码推送成功!"
} else {
    Write-Host "\n推送失败。错误代码: $LASTEXITCODE"
    Write-Host "可能是因为需要输入凭据或网络问题。"

    # 选项2: 配置SSH密钥 (推荐长期解决方案)
    Write-Host "\n=== 选项2: 配置SSH密钥认证 (推荐) ==="
    Write-Host "1. 生成SSH密钥:"
    Write-Host "   $gitPath ssh-keygen -t rsa -b 4096 -C \"yuzh0618@126.com\""
    Write-Host "2. 按Enter键接受默认位置和空密码"
    Write-Host "3. 复制公钥到剪贴板:"
    Write-Host "   clip < $HOME\.ssh\id_rsa.pub"
    Write-Host "4. 打开Gitee设置页面添加SSH密钥: https://gitee.com/profile/sshkeys"
    Write-Host "5. 更新远程仓库URL为SSH形式:"
    Write-Host "   $gitPath remote set-url origin git@gitee.com:yuzh0618/mess-mcp.git"
    Write-Host "6. 再次尝试推送:"
    Write-Host "   $gitPath push -u origin master"
}

pause